# Maintainer: Martijn Braam <martijn@brixit.nl>
# Co-Maintainer: Luca Weiss <luca@z3ntu.xyz>
# Co-Maintainer: Bart Ribbers <bribbers@disroot.org>
# Co-Maintainer: Oliver Smith <ollieparanoid@postmarketos.org>
_flavor=postmarketos-allwinner
_config="config-$_flavor.$CARCH"
pkgname=linux-$_flavor
pkgver=5.10.12_git20210130
pkgrel=4
_tag="orange-pi-5.10-20210130-2109"
pkgdesc="Kernel fork with Pine64 patches (megi's tree, slightly patched)"
arch="aarch64"
_carch="arm64"
url="https://megous.com/git/linux/"
license="GPL-2.0-only"
makedepends="
	bison
	devicepkg-dev
	findutils
	flex
	installkernel
	openssl-dev
	perl
	rsync
	xz
	"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-anbox"
source="$pkgname-$_tag.tar.gz::https://github.com/megous/linux/archive/$_tag.tar.gz
	config-$_flavor.aarch64
	0001-dts-add-dontbeevil-pinephone-devkit.patch
	0002-dts-add-pinetab-dev-old-display-panel.patch
	0004-dts-pinetab-add-missing-bma223-ohci1.patch
	0005-dts-pinetab-make-audio-routing-consistent-with-pinep.patch
	0006-arm64-dts-allwinner-Add-bluetooth-node-to-the-PineTa.patch
	0007-dts-pinephone-remove-bt-firmware-suffix.patch
	0008-media-ov5640-Implement-autofocus.patch
	0009-leds-gpio-set-max_brightness-to-1.patch
	0010-dts-pinephone-Add-pine64-pinephone-to-compat-list.patch
	0011-dts-pinephone-drop-modem-power-node.patch
	0012-dts-headphone-jack-detection.patch
	0013-fix-pogopin-i2c.patch
	"
subpackages="$pkgname-dev"
builddir="$srcdir/linux-$_tag"

prepare() {
	default_prepare

	REPLACE_GCCH=0 \
		. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor" \
		CFLAGS_MODULE=-fno-pic
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor"

	make -j1 modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"
}

dev() {
	provides="linux-headers"
	replaces="linux-headers"

	cd $builddir

	# https://github.com/torvalds/linux/blob/master/Documentation/kbuild/headers_install.rst
	make -j1 headers_install \
		ARCH="$_carch" \
		INSTALL_HDR_PATH="$subpkgdir"/usr
}

sha512sums="3cbab8dfc280cdbdfb84f028a41c649e43d57841e4cf9dd8c1476f07b733fc3975587ca9930612aa0151c1d543b28636378c363f06b7ed8a2c1ac97efebf7bc9  linux-postmarketos-allwinner-orange-pi-5.10-20210130-2109.tar.gz
3a8ccd45317f49ad7416b499a4c766bfffecc3449518e2c7be809d3537ece2d0c7d3da6bbdfb85f7494c294563497f84f1f311cbfded056018248cee31c6fed2  config-postmarketos-allwinner.aarch64
6b96dcdca84f0581d1f6354dfb752ef382b2a70793e881233e71c2af0c58d0eed965be7a494308a639e2e9035e46535f659e0c1721c0e3b8444a2ac981d7dc99  0001-dts-add-dontbeevil-pinephone-devkit.patch
5cd62667ebe1d5213d5d89423fe2a810c55fa84a238790af5f087b31cee3a3db66bcaba14001c345731bc1212060f74c0629433403be2485a5bbd4f0dd1c4f65  0002-dts-add-pinetab-dev-old-display-panel.patch
10eb10fe09258e524b8770961e44bcda55189f86b0f21cf12c831beb94e9b81c66857771bbe75833d56a7bd44907efceb0e1c4022fcaaf8f1d106a83ec8a19eb  0004-dts-pinetab-add-missing-bma223-ohci1.patch
26bd19eb7849ad59ac73a002edeb5d015630c0f802b4da1ec75a01581aeb406350097b5e37ef5c0981cc503cdbfc4d24d446c193a533f01e3e4b51426c9e192e  0005-dts-pinetab-make-audio-routing-consistent-with-pinep.patch
79f244794906b84f2033b04429f9bf187f171291c8f808a65f6d2c3a9b8a029eb0460f281148ff4a43c12be4fac3d78fcc4ddfa4c14e687a3f7fc310a5921048  0006-arm64-dts-allwinner-Add-bluetooth-node-to-the-PineTa.patch
11e3210958afcd9a04885f364d9ce707845173430581601cc8d08451529f80aab137f1c578ab3453e7249fe38001eb6aafe728ba5e34e39b65c7e47a3ecd9fda  0007-dts-pinephone-remove-bt-firmware-suffix.patch
510e1cf463485315f99dfc86511fb7271591159c39cf1bbeecbc1056f8861c35603d61946f3488bfbb7a779ce9324c69d230fa159386b7920f866b47ada444a4  0008-media-ov5640-Implement-autofocus.patch
6dee374e8459279e2e61894ab9146574283dad61605e4547a1258dd09e02646e46712059431b4086aebb95d24ab44c8b5dc21aa9d004f0190f864045a20b336a  0009-leds-gpio-set-max_brightness-to-1.patch
27c091b4fd306b5f6fbadac5881ecc5465804ea910eb299445f7d4f04d09e05b8cb708bf4ac24f9ae2a77afa287bfbebe691f6d90db189896c6951ff8f30bcf5  0010-dts-pinephone-Add-pine64-pinephone-to-compat-list.patch
1d0683871027bd13e03e469fc23c3394b3dbfb48115e19b03638f68970ccfa9583b70ab21d76e68973af803d5387f474f4fe58c90e58985f96c6aec8489aa96a  0011-dts-pinephone-drop-modem-power-node.patch
c93490ebfd7405df2784d78b45bc7ddf985cfa270d0d94c054002f582541f11d28fe216db849cae99d78c3250187d667f305f8a4848d505d0a69a0cbc559be82  0012-dts-headphone-jack-detection.patch
e64d06272ce1e295d8bd444611216ac33c99ad200bdffa2c3e777e9045a744ec66f7908355c1d4a1a85a94f2c4dbc4c1e6ba0e0054348aef52dc8dd6350be444  0013-fix-pogopin-i2c.patch"
